package com.spirng.leetcode.day07;

public class Test108 {
    public static void main(String[] args) {
        Test108 test108 = new Test108();
        test108.sortedArrayToBST(new int[]{0,1,2});
    }
    public TreeNode sortedArrayToBST(int[] nums) {
        return creatTree(nums,0, nums.length-1);
    }
    public TreeNode creatTree(int[] nums,int begin,int end){//区间左闭右闭
        if(begin>end){
            return null;
        }
        int res=(begin+end)/2;
        TreeNode node = new TreeNode(res);
        node.left=creatTree(nums,begin,res-1);
        node.right=creatTree(nums, res+1,end);
        return node;
    }
}
